package priv.pront.code.national.acwing.base;

import java.util.Scanner;

public class A843_N皇后问题2 {

        static int n;
        static char[][] g;
        static boolean[] row, col, dg, udg;
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            n = scanner.nextInt();
            g = new char[n][n];
            col = new boolean[n];
            row = new boolean[n];
            dg = new boolean[20];
            udg = new boolean[20];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    g[i][j] = '.';
            dfs(0,0,0);
        }
        private static void dfs(int x, int y, int s) {
            if(y == n){
                y = 0;
                x++;
            }
            if(x == n){
                if(s == n){
                    for(int i = 0;i < n; i++)System.out.println(g[i]);
                    System.out.println();
                }
                return;
            }
            dfs(x, y + 1, s);
            if(!row[x] && !col[y] && !dg[x + y] && !udg[n - y + x]){
                g[x][y] = 'Q';
                row[x] = col[y] = dg[x + y] = udg[n - y + x] = true;
                dfs(x,y + 1, s + 1);
                row[x] = col[y] = dg[x + y] = udg[n - y + x] = false;
                g[x][y] = '.';

            }
        }

}
